import unittest
from api.employee import EmployeeAPI
from utils import common_assert


class TestEmployee(unittest.TestCase):
    employee_id = None
    # employee_id = 1500023766741278720

    def setUp(self):
        self.employee_api = EmployeeAPI()

    # 添加员工测试用例
    def test01_add_employee(self):
        add_employee_data = {
            "username": "mmsmdEEE00001",
            "mobile": "10031392701",
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "32089",
            "departmentName": "销售",
            "departmentId": "1266699057968001024",
            "correctionTime": "2020-07-30T16:00:00.000Z"
        }
        response = self.employee_api.add_employee(add_employee_data=add_employee_data)
        print(response.json())
        # 断言
        common_assert(self,response,200,True,10000,"操作成功")

        # 提取员工id
        TestEmployee.employee_id = response.json().get("data").get("id")
        print(TestEmployee.employee_id)

    # 修改员工测试用例
    def test02_update_employee(self):
        update_employee_data = {
            "username": "mmsmdQQ87"
        }
        response = self.employee_api.update_employee(TestEmployee.employee_id, update_employee_data)
        print(response.json())
        # 断言
        common_assert(self, response, 200, True, 10000, "操作成功")

    # 查询员工测试用例
    def test03_get_employee(self):
        response = self.employee_api.get_employee(TestEmployee.employee_id)
        print(response.json())
        # 断言
        common_assert(self, response, 200, True, 10000, "操作成功")

    # 删除员工测试用例
    def test04_delete_employee(self):
        response = self.employee_api.delete_employee(TestEmployee.employee_id)
        print(response.json())
        # 断言
        common_assert(self,response,200,True,10000,"操作成功")

